package org.dromara.oce.domain.dto;

import cn.hutool.core.util.NumberUtil;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 短剧每日消耗记录表  --  返回实体
 */
@Data
public class GetOceEverydayCostCensusDramaDataDTO implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 当日时间戳
     */
    private Long thatdayTimestamp;
    /**
     * 当日日期
     */
    private String thatdayDate;
    /**
     * 账户消耗
     */
    private BigDecimal cost;
    /**
     * 当日充值
     */
    private BigDecimal thatdayTotalAmount;
    /**
     * 当日分成金额
     */
    private BigDecimal thatdayDividendAmount;
    /**
     * 当日利润金额
     */
    private BigDecimal thatdayProfitAmount;
    /**
     * 当日付款人数
     */
    private BigDecimal thatdayPaidUseNum;
    /**
     * 当日IAA总收入
     */
    private BigDecimal iaaTotalAmount = BigDecimal.ZERO;
    /**
     * 当日IAA分成金额
     */
    private BigDecimal iaaDividendAmount = BigDecimal.ZERO;
    /**
     * 转化数
     */
    private Integer convert;
    /**
     * 转化成本
     */
    private BigDecimal convertCost;
    /**
     * 付费次数
     */
    private Integer gamePayCount;
    /**
     * 短剧名称
     */
    private String dramaTitle;

    /**
     * 回本率
     * IAP回本率 = 总分成金额 / 总消耗金额
     * IAA回本率=（总分成金额+广告总分成金额）/总消耗金额
     */
    private BigDecimal extRecoveryRate = BigDecimal.ZERO;

    /**
     * 回传率
     * 回传率 = 转化数 / 当日付款人数
     */
    private BigDecimal returnRate = BigDecimal.ZERO;

    public void setReturnRate() {
        this.returnRate = this.thatdayPaidUseNum.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : new BigDecimal(this.convert).divide(this.thatdayPaidUseNum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
    }

    public void setRecoveryRate() {
        try {
            BigDecimal costTemp = this.cost;
            if (NumberUtil.equals(this.cost, BigDecimal.ZERO)) {
                costTemp = new BigDecimal("1");
            }else {
//                costTemp = cost.divide(new BigDecimal("1.015"), 4, RoundingMode.HALF_UP);
            }
            this.extRecoveryRate = (this.iaaDividendAmount.add(this.thatdayTotalAmount)).divide(costTemp, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
        } catch (Exception ignored) {
        }
    }

}
